package com.ruoyi;

import com.ruoyi.column.entity.Column;
import com.ruoyi.column.service.ColumnService;
import com.ruoyi.form.entity.ClassForm;
import com.ruoyi.form.service.ClassFormService;
import com.ruoyi.hov.entity.HovSearchResultSet;
import com.ruoyi.hov.service.HovService;
import com.ruoyi.query.entity.ReturnQuery;
import com.ruoyi.query.service.QueryService;
import com.ruoyi.util.ReflectUtil;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * **********************
 * * Author: XiaShiLong *
 * * Date  : 2021-03-26 *
 * * Time  : 14:16      *
 * * to    : lz&xm      *
 * **********************
 **/
@Service
public class DynamicListDefaultServiceImpl implements DynamicListDefaultService {

    private final ColumnService columnService;

    private final QueryService queryService;

    private final ClassFormService classFormService;

    private final HovService hovService;

    public DynamicListDefaultServiceImpl(ColumnService columnService, QueryService queryService, ClassFormService classFormService, HovService hovService) {
        this.columnService = columnService;
        this.queryService = queryService;
        this.classFormService = classFormService;
        this.hovService = hovService;
    }

    /**
     * 获取动态列表
     *
     * @param menuId    菜单id
     * @param classPath 当前对象路径
     * @return List
     */
    public List<Column> table(Long menuId, String classPath) {
        return columnService.getTable(classPath, menuId);
    }

    /**
     * 获取当前对象查询属性
     *
     * @param menuId    菜单id
     * @param classPath 当前对象路径
     * @return ReturnSelect <see>ReturnSelect</see>
     */
    public ReturnQuery getQuery(Long menuId, String classPath) {
        return queryService.getQuery(ReflectUtil.getClass(classPath), menuId);
    }

    /**
     * 获取表单集合
     *
     * @param menuId    菜单id
     * @param classPath 当前对象路径
     * @return List
     */
    @Override
    public List<ClassForm> getForm(Long menuId, String classPath) {
        return classFormService.getForm(menuId, classPath);
    }

    /**
     * hov查询
     *
     * @param hovId      hovId
     * @param searchText 查询文本
     * @return <see>HovSearchResultSet</see>
     */
    @Override
    public HovSearchResultSet hovSearch(int page, int size, Long hovId, String searchText) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        return hovService.hovSearch(page, size, hovId, searchText);
    }
}
